<template>
    <el-dialog
            :title="!dataForm.disclosureId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="信息披露ID" prop="disclosureId">
                        <el-input v-model.number="dataForm.disclosureId" placeholder="信息披露ID"></el-input>
                </el-form-item>
                <el-form-item label="市场成员ID" prop="memberId">
                        <el-input v-model.number="dataForm.memberId" placeholder="市场成员ID"></el-input>
                </el-form-item>
                <el-form-item label="披露时间" prop="disclosureDate">
                        <el-date-picker
                                v-model="dataForm.disclosureDate"
                                type="datetime"
                                placeholder="披露时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="信息类型（public: 公开信息；general: 公众信息；private: 私有信息）" prop="informationType">
                        <el-input v-model="dataForm.informationType" placeholder="信息类型（public: 公开信息；general: 公众信息；private: 私有信息）"></el-input>
                </el-form-item>
                <el-form-item label="披露状态（approved: 已通过；pending: 待审核；rejected: 已拒绝）" prop="status">
                        <el-input v-model="dataForm.status" placeholder="披露状态（approved: 已通过；pending: 待审核；rejected: 已拒绝）"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="信息披露内容" prop="informationContent">
                        <el-input v-model="dataForm.informationContent" placeholder="信息披露内容"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            disclosureId: null,
            memberId: null,
            disclosureDate: null,
            informationType: null,
            status: null,
            createdAt: null,
            updatedAt: null,
            informationContent: null
          },
          dataRule: {
            disclosureId: [
                        { required: true, message: '信息披露ID不能为空', trigger: 'blur' }
            ],
            memberId: [
                        { required: true, message: '市场成员ID不能为空', trigger: 'blur' }
            ],
            disclosureDate: [
                        { required: true, message: '披露时间不能为空', trigger: 'blur' }
            ],
            informationType: [
                        { required: true, message: '信息类型（public: 公开信息；general: 公众信息；private: 私有信息）不能为空', trigger: 'blur' }
            ],
            status: [
                        { required: true, message: '披露状态（approved: 已通过；pending: 待审核；rejected: 已拒绝）不能为空', trigger: 'blur' }
            ],
            createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ],
            updatedAt: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
            ],
            informationContent: [
                        { required: true, message: '信息披露内容不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.disclosureId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.disclosureId = id || 0
            if (this.dataForm.disclosureId) {
              this.$http({
                url: this.$http.adornUrl(`/app/information_disclosure/info/${this.dataForm.disclosureId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appinformationdisclosure
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/information_disclosure/${!this.dataForm.disclosureId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>